package com.kltn.zigo.data.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kltn.zigo.R;
import com.kltn.zigo.data.IP;
import com.kltn.zigo.data.loader.PlaceLoader;
import com.kltn.zigo.data.loader.PlaceMapLoader;
import com.kltn.zigo.process.ImageLoader;

public class PlaceMapAdapter extends BaseAdapter{
    
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    private PlaceMapLoader placeloader;
    public ImageLoader imageLoader; 
    
    public PlaceMapAdapter(Activity a, PlaceMapLoader pl) {
        activity = a;
        data=pl.GetPlace();
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
        placeloader = pl;        
    }
    
    public PlaceMapAdapter(Activity a, PlaceMapLoader pl, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
        placeloader = pl;
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.item_list_place, null);

        TextView place_id = (TextView)vi.findViewById(R.id.tvID);
        TextView place_name = (TextView)vi.findViewById(R.id.tvPlaceName);
        TextView address = (TextView)vi.findViewById(R.id.tvPlaceAddress); 
        TextView count_like = (TextView)vi.findViewById(R.id.tvPlaceLike); 
        TextView count_comment = (TextView)vi.findViewById(R.id.tvPlaceComment);
        TextView rating_point = (TextView)vi.findViewById(R.id.tvPlacePoint); 
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); 
        
        HashMap<String, String> place = new HashMap<String, String>();
        place = data.get(position);
        String Url_avatar = IP.get_IP() + IP.get_path_avatar() + place.get(placeloader.TAG_NAME_AVATAR);
        // Setting all values in listview
        place_id.setText(place.get(placeloader.TAG_PLACE_ID));
        place_name.setText(place.get(placeloader.TAG_PLACE_NAME));
        address.setText(place.get(placeloader.TAG_ADDRESS));
        count_like.setText(place.get(placeloader.TAG_COUNT_LIKE));
        count_comment.setText(place.get(placeloader.TAG_COUNT_COMMENT));
        rating_point.setText(place.get(placeloader.TAG_POINT_RATING));
        imageLoader.DisplayImage(Url_avatar , thumb_image);
        return vi;
    }

}